package com.example.bbang.controller;

import com.example.bbang.common.CommonResult;
import com.example.bbang.entity.Order;
import com.example.bbang.entity.Shenshu;
import com.example.bbang.mapper.ShenshuMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/shenshu")
public class ShenshuController {
    @Resource
    ShenshuMapper shenshuMapper;

    @PostMapping("add")
    public CommonResult add(Shenshu shenshu){
         shenshuMapper.add(shenshu);

        System.out.println("加shenshu成功:");
        return CommonResult.ok("添加shenshu成功");
    }


    @GetMapping("/pagename")
    public CommonResult findPageBySenshu(@RequestParam Integer pageNum,@RequestParam Integer pageSize,@RequestParam String shenshu){
        System.out.println(pageNum+"和"+pageSize+"和"+shenshu);
        // pageNum = (pageNum-1);
        return CommonResult.ok(shenshuMapper.findPageBySenshu(pageNum,pageSize,shenshu)) ;

    }

    @GetMapping("/pagenameid")
    public CommonResult findPageBySenshu(@RequestParam Integer shenshuid){
        System.out.println(shenshuid);
        // pageNum = (pageNum-1);
        return CommonResult.ok(shenshuMapper. findPageBySenshuID(shenshuid)) ;

    }


    @PostMapping ("/delete")
    public CommonResult deleteById(Shenshu shenshu){
        shenshuMapper.deleteById(shenshu);
        return CommonResult.ok("success") ;
    }

    @GetMapping("/getShenshuCount")
    public CommonResult getShenshuCount(){
        return CommonResult.ok(shenshuMapper.getShenshuCount());
    }
}
